﻿using Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Utilities.Tests
{
    [TestClass()]
    public class JsonConverterTest
    {
        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        enum Importance
        {
            NotImportant = 0,
            Important = 1,
            VeryImportant = 2,
            SuperImportant = 3
        }

        [TestMethod()]
        public void JsonConverterConvertTest()
        {
            Assert.AreEqual("null", JsonConverter.Convert(null));
            Assert.AreEqual(@"""""", JsonConverter.Convert(string.Empty));
            Assert.AreEqual("true", JsonConverter.Convert(true));
            Assert.AreEqual("false", JsonConverter.Convert(false));
            Assert.AreEqual(@"""Hello O'Brian!""", JsonConverter.Convert("Hello O'Brian!"));
            Assert.AreEqual("123", JsonConverter.Convert(123));
            Assert.AreEqual("123.56", JsonConverter.Convert(123.560));
            Assert.AreEqual("-123", JsonConverter.Convert(-123));
            Assert.AreEqual("-123.56", JsonConverter.Convert(-123.560));

            Assert.AreEqual(@"""Hello O\\Brian!""", JsonConverter.Convert("Hello O\\Brian!"));
            Assert.AreEqual("\"Hello O\\\"Brian!\"", JsonConverter.Convert(@"Hello O""Brian!"));
            Assert.AreEqual(@"""Hello O/Brian!""", JsonConverter.Convert("Hello O/Brian!"));
            Assert.AreEqual("\"Hello O\\bBrian!\"", JsonConverter.Convert("Hello O\bBrian!"));
            Assert.AreEqual("\"Hello O\\fBrian!\"", JsonConverter.Convert("Hello O\fBrian!"));

            Assert.AreEqual("\"Hello\\rSarah!\"", JsonConverter.Convert("Hello\rSarah!"));
            Assert.AreEqual("\"Hello\\nSarah!\"", JsonConverter.Convert("Hello\nSarah!"));
            Assert.AreEqual("\"Hello\\r\\nSarah!\"", JsonConverter.Convert(
@"Hello
Sarah!"));
            Assert.AreEqual("\"Hello\\r\\nSarah!\"", JsonConverter.Convert("Hello\r\nSarah!"));        
            Assert.AreEqual("\"Hello\\tSarah!\"", JsonConverter.Convert("Hello\tSarah!"));

            Assert.AreEqual("3", JsonConverter.Convert(Importance.SuperImportant));

            Assert.AreEqual("3/4/2012 7:13:34 PM", JsonConverter.Convert(new DateTime(2012, 3, 4, 19, 13, 34, 678)));
        }
    }
}
